<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/jspcommon.jsp"%>
<%@include file="../common/jscss.jsp"%>
<script type="text/javascript" src="/thirdparty/My97DatePicker/WdatePicker.js"></script>

<style type="text/css">
    .l-table-edit {font-size: 12px;margin: auto;}
 	.l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .error{color:red}
</style>
<input type="button" value="增加日期" onclick="addTime();" class="l-button l-button-submit"/>
	<input name="id" type="hidden" id="id" value="${product.id}" />
	
	<table cellpadding="0" cellspacing="0" class="l-table-edit" id="time_table">
		<c:forEach items="${tpList}" var="productPrice" varStatus="status">
			<tr>
				<td align="right" class="l-table-edit-td">
					日期: <input name="sp_date" type="text"  id="sp_date${status.index}" value="${productPrice.spDate}" ltype="text" onclick="WdatePicker({el:'sp_date${status.index}',dateFmt:'yyyy-MM-dd',readOnly:true});"/>
				</td>
				<td align="left" class="l-table-edit-td">
					价格: <input name="price_a" type="text" id="price_a${status.index}" value="${productPrice.priceA}" ltype="text"  />
				</td>
				<td><a href="javascript:;" onclick="delTime(this);">删除</a></td>
			</tr>
		</c:forEach>
		
	

		
	</table>
	<br />
	<input type="button" value="保存" id="Button1" class="l-button l-button-submit" onclick="savePrice();"/>
	<input type="button" value="取消" class="l-button l-button-submit" style="margin-left: 10px;" onclick="javascript:parent.dialog_ae.close();"/>


<script type="text/javascript">
	var times = ${fn:length(tpList)};
	function addTime(){
		var html = '<tr><td align="right" class="l-table-edit-td">'
				   +'日期: <input name="sp_date" type="text"  id="sp_date'+times+'" value="" ltype="text" onclick="WdatePicker({el:\'sp_date'+times+'\',dateFmt:\'yyyy-MM-dd\',readOnly:true});"/>'
				   +'</td>'
				   +'<td align="left" class="l-table-edit-td">'
				   +'价格: <input name="price_a" type="text" id="price_a'+times+'" value="" ltype="text"  />'
				   +'</td>'
				   +'<td><a href="javascript:;" onclick="delTime(this);">删除</a></td>'
				   +'</tr>';
		$("#time_table").append(html);
		times+=1;
	}
	
	function delTime(self){
		$(self).parent().parent().remove();
	}
	
	function savePrice(){
		var tpList = new Array();
		$("#time_table tr").each(function(){
			var sp_date = $(this).find("[name='sp_date']").val();
			var price_a = $(this).find("[name='price_a']").val();
			var price_c = $(this).find("[name='price_c']").val();
			var productPrice = {
				productId : '${productId}',
				spDate : sp_date,
				priceA : price_a
			}
			tpList.push(productPrice);
		});
		var tpAll = {
			productId : '${productId}',
			tpList : tpList
		}
		$.post("/misc/product/savePrice.htm", {
						tpList : escape($.toJSON(tpList)),
						productId :'${productId}'
					}, function(data) {
						if (data == 'success') {
							alert("保存成功！");
							parent.dialog_ae.close();
						} else {
							alert("详细价格保存失败，请检查是否有重复日期！");
						}
					});
	}
</script>
